﻿using System;
using System.Collections.Generic;
using System.Data;

using CoreLab.Oracle; //using Devart.Data.Oracle; //using Oracle.DataAccess.Client; 
//using Oracle.DataAccess.Types;

using LMD.Constant;
using LMD.Lib.DataClass;
using LMD.Lib.Oracle;

namespace DBQuery
{
    /// <summary>
    /// Summary description for FeedSourceTable
    /// </summary>
    public static class FeedSourceTable
    {

        public static int SaveFeedSource(String sxName, String sxURL)
        {
            return SaveFeedSource(new DBLib(), sxName, sxURL);
        }
        public static int SaveFeedSource(DBLib dbl, String sxName, String sxURL)
        {
            List<OracleParameter> lsParams = new List<OracleParameter>();

            lsParams.Add(new OracleParameter());
            lsParams[lsParams.Count - 1].ParameterName = "out_new_id";
            lsParams[lsParams.Count - 1].OracleDbType = OracleDbType.Number;
            lsParams[lsParams.Count - 1].Direction = ParameterDirection.Output;

            lsParams.Add(new OracleParameter());
            lsParams[lsParams.Count - 1].ParameterName = "in_NAME";
            lsParams[lsParams.Count - 1].OracleDbType = OracleDbType.VarChar;
            lsParams[lsParams.Count - 1].Value = sxName;

            lsParams.Add(new OracleParameter());
            lsParams[lsParams.Count - 1].ParameterName = "in_URL";
            lsParams[lsParams.Count - 1].OracleDbType = OracleDbType.VarChar;
            lsParams[lsParams.Count - 1].Value = sxURL;

            lsParams.Add(new OracleParameter());
            lsParams[lsParams.Count - 1].ParameterName = "in_CREATE_BY";
            lsParams[lsParams.Count - 1].OracleDbType = OracleDbType.VarChar;
            lsParams[lsParams.Count - 1].Value = ICPUser.ID;

            String sxQuery = "PR_INSERT_FEED_SOURCE";

            dbl.ExecuteProcedure(sxQuery, lsParams.ToArray());
            
            return Convert.ToInt32(lsParams[0].Value);
        }

        public static void UpdateFeedSource(int iFeedSourceId, String sxName, String sxURL)
        {
            UpdateFeedSource(new DBLib(), iFeedSourceId, sxName, sxURL);
        }
        public static void UpdateFeedSource(DBLib dbl, int iFeedSourceId, String sxName, String sxURL)
        {
            List<OracleParameter> lsParams = new List<OracleParameter>();

            lsParams.Add(new OracleParameter());
            lsParams[lsParams.Count - 1].ParameterName = "IN_FEED_SOURCE_ID";
            lsParams[lsParams.Count - 1].OracleDbType = OracleDbType.Number;
            lsParams[lsParams.Count - 1].Value = iFeedSourceId;

            lsParams.Add(new OracleParameter());
            lsParams[lsParams.Count - 1].ParameterName = "in_NAME";
            lsParams[lsParams.Count - 1].OracleDbType = OracleDbType.VarChar;
            lsParams[lsParams.Count - 1].Value = sxName;

            lsParams.Add(new OracleParameter());
            lsParams[lsParams.Count - 1].ParameterName = "in_URL";
            lsParams[lsParams.Count - 1].OracleDbType = OracleDbType.VarChar;
            lsParams[lsParams.Count - 1].Value = sxURL;

            lsParams.Add(new OracleParameter());
            lsParams[lsParams.Count - 1].ParameterName = "in_UPDATE_BY";
            lsParams[lsParams.Count - 1].OracleDbType = OracleDbType.VarChar;
            lsParams[lsParams.Count - 1].Value = ICPUser.ID;

            String sxQuery = "PR_UPDATE_FEED_SOURCE";

            dbl.ExecuteProcedure(sxQuery, lsParams.ToArray());
            
        }

        public static void DeleteFeedSource(int iFeedSourceId)
        {
            DeleteFeedSource(new DBLib(), iFeedSourceId);
        }
        public static void DeleteFeedSource(DBLib dbl, int iFeedSourceId)
        {
            List<OracleParameter> lsParams = new List<OracleParameter>();

            OracleParameter param = new OracleParameter();
            param.ParameterName = "prmID";
            param.OracleDbType = OracleDbType.Number;
            param.Value = iFeedSourceId;

            String sxQuery = " delete from FEED_SOURCE where FEED_SOURCE_ID = :prmID";

            dbl.ExecuteNonQuery(sxQuery, param);
            
        }

        public static void ToggleFeedSource(int iFeedSourceId)
        {
            ToggleFeedSource(new DBLib(), iFeedSourceId);
        }
        public static void ToggleFeedSource(DBLib dbl, int iFeedSourceId)
        {
            List<OracleParameter> lsParams = new List<OracleParameter>();

            OracleParameter param = new OracleParameter();
            param.ParameterName = "in_FEED_SOURCE_ID";
            param.OracleDbType = OracleDbType.Number;
            param.Value = iFeedSourceId;

            String sxQuery = "PR_TOGGLE_FEED_SOURCE";

            dbl.ExecuteProcedure(sxQuery, param);
            
        }
    }
}